package com.lgkj.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lgkj.R;
import com.lgkj.bean.meitao.GoodsListTypeBean;
import com.lgkj.utils.CommonUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/8/20 0020.
 */

public class GoodsListTypeAdapter extends BaseAdapter {
    private Context context;
    private List<GoodsListTypeBean.DataBeanX.DataBean> data;

    public void setData(List<GoodsListTypeBean.DataBeanX.DataBean> data) {
        this.data.addAll(data);
    }
    public void dataClean(){
        this.data.clear();
    }
    public GoodsListTypeAdapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public GoodsListTypeBean.DataBeanX.DataBean getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_hot, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        GoodsListTypeBean.DataBeanX.DataBean bean = data.get(i);
        viewHolder.tvOldPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中间横线

        viewHolder.tvOldPrice.setText("Y" + bean.getOld_price());
        viewHolder.tvTitle.setText(bean.getGoods_name());
        viewHolder.tvPrice.setText("会员价:￥" + bean.getPrice());
        viewHolder.tvSale.setText("销量:" + bean.getSales());
        String url = bean.getPhotos().get(0);
        Log.i("getView: ", url);
        CommonUtils.LoadImage(context, viewHolder.ivImg, url, R.mipmap.shop_item_defult);
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.iv_img)
        ImageView ivImg;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_old_price)
        TextView tvOldPrice;
        @BindView(R.id.tv_sale)
        TextView tvSale;
        @BindView(R.id.tv_price)
        TextView tvPrice;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
